package util

import (
	"encoding/json"
)

func MakeSessionId(from uint32, to uint32) uint64 {
	big := uint64(0)
	little := uint64(0)
	if from > to {
		big = uint64(from) << 32
		little = uint64(to)
	} else {
		big = uint64(to) << 32
		little = uint64(from)
	}
	return big | little
}

func ToJson(v interface{}) string {
	marshal, err := json.Marshal(v)
	if err != nil {
		return ""
	}
	return string(marshal)
}

var MysqlIdGenerate = &mysqlIdGenerate{}

// 申请id
func ApplyId() (uint32, error) {
	return MysqlIdGenerate.GetId()
}
